package com.tanhua.server.controller;

import com.tanhua.domain.db.UserInfo;
import com.tanhua.domain.vo.PageResult;
import com.tanhua.domain.vo.SettingsVo;
import com.tanhua.server.service.SettingsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * 通用设置控制层
 */
@RestController
@RequestMapping("/users")
public class SettingsController {

    @Autowired
    private SettingsService settingsService;


    /**
     * 查询通用设置
     */
    @RequestMapping(value = "/settings",method = RequestMethod.GET)
    public ResponseEntity querySettings(){
        SettingsVo settingsVo =  settingsService.querySettings();
        return ResponseEntity.ok(settingsVo);
    }

    /**
     * 通知设置-修改是否通知
     */
    @RequestMapping(value = "/notifications/setting",method = RequestMethod.POST)
    public ResponseEntity updateNotification(@RequestBody Map map){
        boolean likeNotification= (boolean)map.get("likeNotification");
        boolean pinglunNotification= (boolean)map.get("pinglunNotification");
        boolean gonggaoNotification= (boolean)map.get("gonggaoNotification");
        settingsService.updateNotification(likeNotification,pinglunNotification,gonggaoNotification);
        return ResponseEntity.ok(null);
    }


    /**
     * 黑名单 - 翻页列表
     */
    @RequestMapping(value = "/blacklist",method = RequestMethod.GET)
    public ResponseEntity queryBlackList(@RequestParam(defaultValue = "1") int page,@RequestParam(defaultValue = "10") int pagesize){
        PageResult<UserInfo> pageResult =  settingsService.queryBlackList(page,pagesize);
        return ResponseEntity.ok(pageResult);
    }

    /**
     * 黑名单 - 移除黑名单用户
     */
    @RequestMapping(value = "/blacklist/{uid}",method = RequestMethod.DELETE)
    public ResponseEntity deleteBlackUser(@PathVariable("uid") Long blackUserId){
         settingsService.deleteBlackUser(blackUserId);
        return ResponseEntity.ok(null);
    }


    /**
     * 陌生人问题修改
     */
    @RequestMapping(value = "/questions",method = RequestMethod.POST)
    public ResponseEntity updateQuestions(@RequestBody Map<String,String> map){
        String content = map.get("content");
        settingsService.updateQuestions(content);
        return ResponseEntity.ok(null);
    }
}
